<template>
	<div class="components-container">
        <div class="header-form">
            <div class="layui-inline">
                <label>汇总日期从</label>
                <el-date-picker v-date v-model="selectData.CdhactualdateGreaterAndEquals" type="date" placeholder="输入日期"/>
              
                 到 <el-date-picker v-date v-model="selectData.CdhactualdateLessAndEquals" type="date" placeholder="输入日期"/>
            </div>
            <el-button type="primary" @click="btnSearch" :disabled="downloadLoading" :loading="this.$store.state.isloading">搜索</el-button>
            <el-button :disabled="this.$store.state.isloading || downloadLoading" @click="btnRepeat">重置</el-button>
        </div>
        <div>
          <ul class="toolList">
            <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
              <el-button type="primary" :disabled="$store.state.isloading || downloadLoading" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
            </li>
            <li>
            <el-button type="primary" @click="exportExcel" :disabled="this.$store.state.isloading">导出Excel</el-button>
            </li>
          </ul>
        </div>
        <dataTable :height="height"  :headList="headList" :isIndex="true" :dataList="dataList" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow" :hiddenPageOrder="false" :hiddenColumn="hiddenColumn"></dataTable>
        <printmodal ref="printPdf"></printmodal>
	</div>
</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-button + .el-button {
  margin-left: 0;
}
.btn {
  text-align: center;
}
</style>
<script>
import dataTable from "@/components/Table/DataTable";
import printmodal from "@/components/Pdf/Print";
import apiBase from "@/api/apiBase.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import { manage } from "@/mixins/managePage.js";
import { PRINT } from "@/components/Pdf/PDF.js";
import sweetModal from "@/components/sweetModal";
const EXPORT = "打印";
export default {
  name: "unitManage",
  mixins: [manage],
  data() {
    return {
      selectData: {
        CdhactualdateGreaterAndEquals:null,
        CdhactualdateLessAndEquals:null
      },
      downloadLoading:false,
      OutDataExcel:[],
      message: null,
      height: "620",  
      sweetModalWidth: 80,
      sweetModalMaxWidth: 1000,
      hiddenColumn: false,
     
    };
  },
  methods: {
    exportExcel() {
      var startTime;
      var endTime;
      if(this.selectData.CdhactualdateGreaterAndEquals){
        startTime = this.selectData.CdhactualdateGreaterAndEquals.toLocaleDateString();
      }else{
        startTime = '空';
      }
      if(this.selectData.CdhactualdateLessAndEquals){
        endTime = this.selectData.CdhactualdateLessAndEquals.toLocaleDateString();
      }else{
        endTime = '空';
      }
      var header = '墓区统计表' + '(' + startTime + '--' + endTime + ')';
       if (this.dataList.length === 0){
          this.$message.error("无导出数据！");
          return;
      }
      this.downloadLoading = true;
      console.log(this.headList);
      console.log(this.OutDataExcel);
      require.ensure([], () => {
        const { export_json_to_excel } = require("@/vendor/Export2Excel");
        export_json_to_excel(this.headList, this.OutDataExcel, header);
        this.downloadLoading = false;
      });
    },
    //功能操作
    operate(order) {
      this.order = order;
      switch (this.order) {
        case EXPORT:
            this.$refs.printPdf.report(PRINT.PDFDRIVERS,this.getDataC());
          break;
       
        default:
      }
    },
      //接运类别
    getFeeders(){
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Code.GetFeederCategory,
        res => {
          this.feeders = res.data.content;
        }
      );
    },
    getColumns() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetDriverStatisticsColumns,
        res => {
          this.headList = res.data.content;
        }
      );
    },
   getDataC(){
      let Data = JSON.parse(JSON.stringify(this.selectData));
      if(Data.RegiskeypointEquals === null || Data.RegiskeypointEquals === undefined) Data.RegiskeypointEquals = 'A';
       Data.CdhactualdateGreaterAndEquals = formatDate(
        Data.CdhactualdateGreaterAndEquals,
        "yyyyMMdd"
      );
      Data.CdhactualdateLessAndEquals = formatDate(
        Data.CdhactualdateLessAndEquals,
        "yyyyMMdd"
      );
      let data = {
        PageIndex: 1,
        PageSize: 100,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: Data
      };
      return data;
    },
    getData() {
      let Data = JSON.parse(JSON.stringify(this.selectData));
      Data.CdhactualdateGreaterAndEquals = formatDate(
        Data.CdhactualdateGreaterAndEquals,
        "yyyyMMdd"
      );
      Data.CdhactualdateLessAndEquals = formatDate(
        Data.CdhactualdateLessAndEquals,
        "yyyyMMdd"
      );

      let data = {
        PageIndex: 1,
        PageSize: -1,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: Data
      };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Report.QueryDriverStatistics,
          res => {
            // this.hiddenColumnInfo = true;
            this.dataList = res.data.content.OutData;
            this.OutDataExcel = res.data.content.OutData;
            this.message = res.data.content.Message;
            this.pageOrder.totalNum = res.data.content.RecordCount;
          }
        );
      
    },
  
    //当前选中行
    selectRow(row) {
      this.currentRow = row;
      this.$emit("selectRow", row, "");
    },
    // dataRepeat(){},
    btnRepeat() {
        this.selectData = {};
        this.getData();
      },
    btnShow(btn){
        switch (btn) {
            case EXPORT:
              return true;
              break;
            default: return false;
          }
      },
    },
  mounted() {
    // this.getAllData();
  },
  components: {
    dataTable,
    sweetModal,
    printmodal
  },
 
  created() {
    this.selectData.CdhactualdateGreaterAndEquals = new Date();
    this.selectData.CdhactualdateGreaterAndEquals.setDate(1);
    this.selectData.CdhactualdateLessAndEquals = new Date();

    // this.getColumns();
    // this.getData();
    this.headList = [{
        "ColumnKey": "UNTNAME",
        "ColumnName": "墓区名称",
        "ColumnOrder": "UNTNAME",
        "ColumnAlign": "center",
        "ColumnWidth": 150
      }, {
        "ColumnKey": "UNTBUILDDATE",
        "ColumnName": "建设时间",
        "ColumnOrder": "UNTBUILDDATE",
        "ColumnAlign": "center",
        "ColumnWidth": 150
      }, {
        "ColumnKey": "ADDNAME",
        "ColumnName": "统计地址",
        "ColumnOrder": "ADDNAME",
        "ColumnAlign": "center",
        "ColumnWidth": 120
      }, {
        "ColumnKey": "UNTTYPE",
        "ColumnName": "类别",
        "ColumnOrder": "UNTTYPE",
        "ColumnAlign": "center",
        "ColumnWidth": 120
      }, {
        "ColumnKey": "UNTGREENRATE",
        "ColumnName": "墓区绿化率",
        "ColumnOrder": "UNTGREENRATE",
        "ColumnAlign": "center",
        "ColumnWidth": 120
      }, {
        "ColumnKey": "UNTAPVTOTALAREA",
        "ColumnName": "审批总面积",
        "ColumnOrder": "UNTAPVTOTALAREA",
        "ColumnAlign": "center",
        "ColumnWidth": 120
      }, {
        "ColumnKey": "UNTLOCATION",
        "ColumnName": "地址",
        "ColumnOrder": "UNTLOCATION",
        "ColumnAlign": "center",
        "ColumnWidth": 200
      }, {
        "ColumnKey": "UNTSURPLUSNUM",
        "ColumnName": "剩余墓穴总量",
        "ColumnOrder": "UNTSURPLUSNUM",
        "ColumnAlign": "center",
        "ColumnWidth": 150
      }, {
        "ColumnKey": "UNTSTATUS",
        "ColumnName": "状态",
        "ColumnOrder": "UNTSTATUS",
        "ColumnAlign": "center",
        "ColumnWidth": 120
      }]
    this.dataList = [{
        "UNTID": "330481X1L1UNT20190506090518704",
        "UNTNAME": "1区",
        "UNTLOCATION": "",
        "UNTTYPE": "开辟生态墓区的公益性公墓",
        "UNTSTATUS": "正常",
        "UNTBUILDDATE": "",
        "UNTGREENRATE": 0.0,
        "UNTAPVTOTALAREA": 0.0,
        "UNTSURPLUSNUM": 0,
        "ADDNAME": "45长安镇",
        "UNTONLINE": 0,
        "UNTONLINEDESC": "未联网"
      }, {
        "UNTID": "330481X1L1UNT20190424085945980",
        "UNTNAME": "2区",
        "UNTLOCATION": "",
        "UNTTYPE": "经营性公墓",
        "UNTSTATUS": "正常",
        "UNTBUILDDATE": "",
        "UNTGREENRATE": 0.0,
        "UNTAPVTOTALAREA": 0.0,
        "UNTSURPLUSNUM": 0,
        "ADDNAME": "45长安镇",
        "UNTONLINE": 0,
        "UNTONLINEDESC": "未联网"
      }, {
        "UNTID": "330481X1L1UNT20190424085925808",
        "UNTNAME": "31区",
        "UNTLOCATION": "",
        "UNTTYPE": "开辟生态墓区的公益性公墓",
        "UNTSTATUS": "正常",
        "UNTBUILDDATE": "",
        "UNTGREENRATE": 0.0,
        "UNTAPVTOTALAREA": 0.0,
        "UNTSURPLUSNUM": 0,
        "ADDNAME": "45长安镇",
        "UNTONLINE": 0,
        "UNTONLINEDESC": "未联网"
      }, {
        "UNTID": "330481X1L1UNT20190424085909777",
        "UNTNAME": "4区",
        "UNTLOCATION": "",
        "UNTTYPE": "开辟生态墓区的公益性公墓",
        "UNTSTATUS": "正常",
        "UNTBUILDDATE": "",
        "UNTGREENRATE": 0.0,
        "UNTAPVTOTALAREA": 0.0,
        "UNTSURPLUSNUM": 0,
        "ADDNAME": "5长安镇",
        "UNTONLINE": 0,
        "UNTONLINEDESC": "未联网"
      }, {
        "UNTID": "330481X1L1UNT20190424085853152",
        "UNTNAME": "5区",
        "UNTLOCATION": "",
        "UNTTYPE": "开辟生态墓区的公益性公墓",
        "UNTSTATUS": "正常",
        "UNTBUILDDATE": "",
        "UNTGREENRATE": 0.0,
        "UNTAPVTOTALAREA": 0.0,
        "UNTSURPLUSNUM": 0,
        "ADDNAME": "3长安镇",
        "UNTONLINE": 0,
        "UNTONLINEDESC": "未联网"
      }, {
        "UNTID": "330481X1L1UNT20190424085828090",
        "UNTNAME": "6区",
        "UNTLOCATION": "",
        "UNTTYPE": "开辟生态墓区的公益性公墓",
        "UNTSTATUS": "正常",
        "UNTBUILDDATE": "",
        "UNTGREENRATE": 0.0,
        "UNTAPVTOTALAREA": 0.0,
        "UNTSURPLUSNUM": 0,
        "ADDNAME": "2长安镇",
        "UNTONLINE": 0,
        "UNTONLINEDESC": "未联网"
      }, {
        "UNTID": "330481X1L1UNT20190424085803824",
        "UNTNAME": "7区",
        "UNTLOCATION": "",
        "UNTTYPE": "开辟生态墓区的公益性公墓",
        "UNTSTATUS": "正常",
        "UNTBUILDDATE": "",
        "UNTGREENRATE": 0.0,
        "UNTAPVTOTALAREA": 0.0,
        "UNTSURPLUSNUM": 0,
        "ADDNAME": "1长安镇",
        "UNTONLINE": 0,
        "UNTONLINEDESC": "未联网"
      }, {
        "UNTID": "330481X1L1UNT20190424085742871",
        "UNTNAME": "8区",
        "UNTLOCATION": "",
        "UNTTYPE": "开辟生态墓区的公益性公墓",
        "UNTSTATUS": "正常",
        "UNTBUILDDATE": "",
        "UNTGREENRATE": 0.0,
        "UNTAPVTOTALAREA": 0.0,
        "UNTSURPLUSNUM": 0,
        "ADDNAME": "2长安镇",
        "UNTONLINE": 0,
        "UNTONLINEDESC": "未联网"
      }, {
        "UNTID": "330481X1L1UNT20190424085716199",
        "UNTNAME": "0区",
        "UNTLOCATION": "",
        "UNTTYPE": "开辟生态墓区的公益性公墓",
        "UNTSTATUS": "正常",
        "UNTBUILDDATE": "",
        "UNTGREENRATE": 0.0,
        "UNTAPVTOTALAREA": 0.0,
        "UNTSURPLUSNUM": 0,
        "ADDNAME": "1长安镇",
        "UNTONLINE": 0,
        "UNTONLINEDESC": "未联网"
      }, {
        "UNTID": "330481X1L1UNT20190424085658387",
        "UNTNAME": "9区",
        "UNTLOCATION": "",
        "UNTTYPE": "开辟生态墓区的公益性公墓",
        "UNTSTATUS": "正常",
        "UNTBUILDDATE": "",
        "UNTGREENRATE": 0.0,
        "UNTAPVTOTALAREA": 0.0,
        "UNTSURPLUSNUM": 0,
        "ADDNAME": "0长安镇",
        "UNTONLINE": 0,
        "UNTONLINEDESC": "未联网"
      }
    ]
    this.getFeeders();
    
  }
};
</script>